/*
 * Copyright 2007 National Bioinformatics Network
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package dgbgui.gui.widgets.visual;

import java.awt.Color;

import dgbgui.gui.DefaultCanvasScene;
import dgbgui.gui.widgets.Widget;
import dgbgui.gui.widgets.layouts.VerticalLayout;
import edu.umd.cs.piccolo.PNode;
import edu.umd.cs.piccolo.activities.PActivity;

@SuppressWarnings("serial")
public class RotatingProgressWidget extends RectangleBorder  {
    
    public static class GearsWidget extends Widget {
        
        public GearsWidget(PNode parent, double outerRadius, double innerRadius) {
            super(parent);
            

            float width = 2.0f;
            for ( int k = 0; k < 12; ++k ) {
                RectangleWidget stub = new RectangleWidget(this,0 + innerRadius,-width/2, outerRadius - innerRadius,width);
                stub.rotateAboutPoint(Math.toRadians(360/12*k), 0, 0);
                stub.setFillColor(new Color(0,0,255,255/12*k));
                stub.setStrokeColor(new Color(0,0,0,0));
            }
        }

    }
    
    public RotatingProgressWidget(PNode parent) {
        super(parent,0,5.0);
        VerticalLayout layout = new VerticalLayout(this,0.0,0.0);
        
        RectangleWidget border = new RectangleWidget(layout,0,0,30,30);
        border.setFillColor(new Color(0,0,0,0));
        border.setStrokeColor(new Color(0,0,0,0));
        
        setStrokeColor(Color.black);
        setFillColor(getDefaultFillColour());
        
        final PNode gears = new GearsWidget(border,10.0,5.0);
        gears.translate(15,15);

        PActivity activity = new PActivity(-1, 100) {
            public void activityStep(long currentTime) {
                super.activityStep(currentTime);
                gears.rotateAboutPoint(Math.toRadians(5),0,0);
            }
        };
        DefaultCanvasScene.getInstance().getLayer().getRoot().addActivity(activity);
    }

    

}
